//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart.Serialization
{
    public class ChartInstanceProvider : IOfficeInstanceProvider
    {
        public IOfficeXmlSerializable ReadInstance(ReadContext context)
        {
            if (context.Reader.NamespaceURI == ChartConstants.ChartNamespaceUri)
            {
                var result = createChartInstance(context);
                if (result != null)
                    result.ReadXml(context);
                return result;

            }
            return null;
        }

        private static IOfficeXmlSerializable createChartInstance(ReadContext context)
        {
            switch (context.ReaderLocalName)
            {
                case "chart":
                    return new AttachedChart();
                default: throw new NotImplementedException();
            }
        }
    }
}